package com.pine.dcts.service;

import com.pine.dcts.common.TaskStatusType;
import com.pine.dcts.model.TaskMeta;
import com.pine.dcts.task.status.TaskStatusUpdator;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xiaoyuan
 * @create 2021/1/13 20:09
 **/
@Setter
@Getter
@Slf4j
public class DefaultTaskRunnerCallback implements TaskRunnerCallback {

    private TaskMeta taskMeta;

    private String message;

    private TaskStatusType taskStatus;

    private TaskStatusUpdator taskStatusUpdator;

    public DefaultTaskRunnerCallback(TaskMeta taskMeta,TaskStatusUpdator taskStatusUpdator) {
        this.taskStatus = TaskStatusType.NOT_START;
        this.taskMeta = taskMeta;
        this.taskStatusUpdator = taskStatusUpdator;
    }

    @Override
    public void callback() {
        try {
            taskStatusUpdator.update(this);
        } catch (Throwable e) {
            log.error("更新任务状态错误", e);
        }
    }
}
